<template xmlns="http://www.w3.org/1999/html">
    <!--新建-->
    <smart-form ref="form_create" method="POST" url="/sys/app/info"
                v-show="operation==='new'" :on-succeed="callback">
      <smart-form-layout require name="appName" label="应用名称">
        <smart-text-view name="appName" placeholder="应用名称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="version" label="版本号">
        <smart-text-view name="version" placeholder="版本号"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="appPage" label="产品主页">
        <smart-text-view name="appPage" placeholder="E.G.: http://www.baidu.com"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="appType" label="文件类型">
        <smart-select name="appType" placeholder="文件类型" options="t_sys_app_info.app_type"></smart-select>
      </smart-form-layout>
      <smart-form-layout require name="roleName" label="文件">
        <smart-file-uploader name="roleName" placeholder="文件"></smart-file-uploader>
      </smart-form-layout>
      <smart-form-layout require name="description" label="简介">
        <smart-text-view type="textarea" name="description" placeholder="简介"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="updateContent" label="更新内容">
        <smart-text-view type="textarea" name="updateContent" placeholder="更新内容"></smart-text-view>
      </smart-form-layout>
    </smart-form>
</template>

<script>


export default {
    components: {}
    , props: {
        // 成功回调，通常是刷新数据表格
        onSucceed: {type: Function, default: undefined}
    }
    , methods: {
        /**
         * 新增/编辑操作成功，关闭当前窗口
         *
         * @param ret 后台响应数据
         */
        callback: function (ret) {
            this.$layers.succeed('操作成功!');
            // 刷新表单列表
            this.onSucceed(ret);
            // 关闭弹窗
            this.$refs.dialog.close();
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'edit') {
                let dialog = {title: `更新 ${row.appName}`};
                this.$refs.dialog.open(dialog).then(() => this.row_data = row);
            } else if (evt === 'new') {
                let dialog = {title: `新建`};
                this.$refs.dialog.open(dialog);
            } else if (evt === 'remove') {
                this.$layers.delete({
                    url: '/sys/app/info',
                    params: {id: row.id}
                }).then(function (result) {
                    this.callback(result);
                });
            } else if (evt === 'download') {

            } else if (evt === 'qr') {
                let dialog = {title: `二维码`};
                this.$refs.dialog.open(dialog);
            }
        }
    }
    , data() {
        return {
            // 操作名称
            operation: undefined
            // 行级数据
            , row_data: undefined
        }
    }
    //end
}
</script>
